<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Captcha extends Controller {
	function Captcha()
	{
		parent::Controller();
		$this->load->library('si_captcha');
	}
	
	function index()
	{
		show_404();
	}
	
	function get_image()
	{
		$this->si_captcha->show();
	}
	
	function get_audio()
	{
		header('Content-type: audio/x-wav');
		header('Content-Disposition: attachment; name="securimage.wav"');
		header('Cache-Control: no-store, no-cache, must-revalidate');
		header('Expires: Sun, 1 Jan 2000 12:00:00 GMT');
		header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
		
		echo $this->si_captcha->getAudibleCode();
	}
	
/**
 * Once you've confirmed that everything is working, you can safely 
 * delete the functions under this comment if you wish.
 */ 	
	function _print_status($supported)
	{
		if ($supported) {
			echo "<span style=\"color: #00f\">Yes!</span>";
		} 
		else 
		{
			echo "<span style=\"color: #f00; font-weight: bold\">No</span>";
		}
	}
		
	function get_test_image()
	{
		if ($this->si_captcha->test_mode !== TRUE)
		{
			show_404();
		}
		
		$im = imagecreate(225, 225);
		$white = imagecolorallocate($im, 255, 255, 255);
		$black = imagecolorallocate($im, 0, 0, 0);
		$red   = imagecolorallocate($im, 255,   0,   0);
		$green = imagecolorallocate($im,   0, 255,   0);
		$blue  = imagecolorallocate($im,   0,   0, 255);
		
		imagearc($im, 100, 120, 200, 200,  0, 360, $black);
		imagearc($im, 100, 120, 150, 150, 25, 155, $red);
		imagearc($im,  60,  95,  50,  50,  0, 360, $green);
		imagearc($im, 140,  95,  50,  50,  0, 360, $blue);
		imagestring($im, 5, 15, 1, 'Securimage Will Work!!', $blue);
		imagestring($im, 2, 5, 20, ':) :) :)', $black);
		imagestring($im, 2, 5, 30, ':) :)', $black);
		imagestring($im, 2, 5, 40, ':)', $black);
		imagestring($im, 2, 150, 20, '(: (: (:', $black);
		imagestring($im, 2, 168, 30, '(: (:', $black);
		imagestring($im, 2, 186, 40, '(:', $black);

		imagepng($im, null, 3);
	}
	
	function compatibility_test()
	{
		if ($this->si_captcha->test_mode !== TRUE)
		{
			show_404();
		}
		?>
<html>
<head>
<title>Securimage Test Script</title>
</head>
<body>
<h2>Securimage Test Script</h2>
<p>
This script will test your PHP installation to see if Securimage will run on your server.
</p>
<ul>
<li>
<strong>GD Support:</strong>
<?php $this->_print_status($gd_support = extension_loaded('gd')); ?>
</li>
<?php if ($gd_support) $gd_info = gd_info(); else $gd_info = array(); ?>
<?php if ($gd_support): ?>
<li>
<strong>GD Version:</strong>
<?php echo $gd_info['GD Version']; ?>
</li>
<?php endif; ?>
<li>
<strong>TTF Support (FreeType):</strong>
<?php $this->_print_status($gd_support && $gd_info['FreeType Support']); ?>
<?php if ($gd_support && $gd_info['FreeType Support'] == false): ?>
<br />No FreeType support.  Cannot use TTF fonts, but you can use GD fonts
<?php endif; ?>
</li> 
<li>
<strong>JPEG Support:</strong>
<?php $this->_print_status($gd_support && $gd_info['JPG Support']); ?>
</li>
<li>
<strong>PNG Support:</strong>
<?php $this->_print_status($gd_support && $gd_info['PNG Support']); ?>
</li>
<li>
<strong>GIF Read Support:</strong>
<?php $this->_print_status($gd_support && $gd_info['GIF Read Support']); ?>
</li>
<li>
<strong>GIF Create Support:</strong>
<?php $this->_print_status($gd_support && $gd_info['GIF Create Support']); ?>
</li>
</ul>
<?php if ($gd_support): ?>
Since you can see this...<br /><br />
<img src="/captcha/get_test_image" alt="Test Image" align="bottom" />
<?php else: ?>
Based on the requirements, you do not have what it takes to run Securimage :(
<?php endif; ?>
</body>
</html>
<?php
	}
	
}

/* End of file captcha.php */
/* Location: ./system/application/captcha.php */